<%
logged_user = results_dic['logged_user']
title = results_dic['html_title']
urls = results_dic['urls_dic']
trans = results_dic['trans_class'].trans
lang_selected = results_dic['trans_class'].selected
links = results_dic['links']
current_page = results_dic['current_page']
%>
<%def name="gen_link(links, current = 'search')">
    % for i in links:
        <%
        name = trans(i[0])
        %>
        % if i[0] == current:
    <li id="current"><a href="${i[1]}">${name}</a></li>\
        % else:
    <li><a href="${i[1]}">${name}</a></li>\
        % endif
    % endfor
</%def>
<html>
    <head>
        <title>MyMolDB - ${trans(title)}</title>
        <meta name="author" content="xiooli" />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="${urls['css_dir']}/style.css" />
    </head>
    <body>
        <script language='javascript'>
            function rannum() {
                return Math.random();
            }
            function GetXmlHttpObject() {
                var xmlHttp=null;
                try {
                    // Chrome, Firefox, Opera 8.0+, Safari
                    xmlHttp=new XMLHttpRequest();
                }
                catch (e) {
                    // Internet Explorer
                    try {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e)
                    {
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                return xmlHttp;
            }
            function get_url(url){
                xmlHttp = GetXmlHttpObject();
                if (xmlHttp!=null && url) {
                    xmlHttp.onreadystatechange = stateChanged;
                    xmlHttp.open("GET", url, true);
                    xmlHttp.send(null);
                }
            }
            function stateChanged() {
                if (xmlHttp.readyState==4) {
                    document.location.reload();
                }
            }
            function chmode(mode) {
                if (mode) {
                    get_url("${urls['chmode_url']}?mode=" + mode + "&sid=" + rannum());
                }
            }
            function chlang(lang) {
                if (lang) {
                    get_url("${urls['trans_url']}?lang=" + lang + "&sid=" + rannum());
                }
            }
            function logout() {
                get_url("${urls['logout_url']}" + "&sid=" + rannum())
            }
            function login() {
                var url = document.location.href;
                document.location.href = "${urls['login_url']}?ref=" + base64encode(url);
            }
            var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
            function base64encode(str) {
                var out, i, len;
                var c1, c2, c3;
                len = str.length;
                i = 0;
                out = "";
                while(i < len) {
                    c1 = str.charCodeAt(i++) & 0xff;
                    if(i == len)
                    {
                        out += base64EncodeChars.charAt(c1 >> 2);
                        out += base64EncodeChars.charAt((c1 & 0x3) << 4);
                        out += "==";
                        break;
                    }
                    c2 = str.charCodeAt(i++);
                    if(i == len)
                    {
                        out += base64EncodeChars.charAt(c1 >> 2);
                        out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
                        out += base64EncodeChars.charAt((c2 & 0xF) << 2);
                        out += "=";
                        break;
                    }
                    c3 = str.charCodeAt(i++);
                    out += base64EncodeChars.charAt(c1 >> 2);
                    out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
                    out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
                    out += base64EncodeChars.charAt(c3 & 0x3F);
                }
                return out;
            }
        </script>
        <div id="wrapheader">
            <div id="topwrapper">
                <div id="tophead"></div>
            </div>
            <div id="nav1">
                <ul>
                    ${gen_link(links, current_page)}
                </ul>
            </div>
        </div>
        <table width="100%" cellpadding="0" id="menubar">
            <tr>
                % if logged_user:
                    <td align="left"><a href="javascript:;" onclick="logout()">${trans('logout')} [${logged_user}]</a>&nbsp;|&nbsp;
                    <a href="${urls['ucpanel_url']}">${trans('user control panel')}</a></td>
                % else:
                    <td align="left"><a href="javascript:;" onclick="login()">${trans('login')}</a>&nbsp;|&nbsp;
                    <a href="${urls['register_url']}">${trans('register')}</a></td>
                % endif
                <td align="right">
                    <span>${trans('language')}</span>
                    <select id="langslct" onchange="chlang(this.options[this.selectedIndex].value)">
                        <option value="zh_CN" ${lang_selected("zh_CN")}>${trans('chinese')}</option>
                        <option value="en_US" ${lang_selected("en_US")}>${trans('english')}</option>
                    </select>
                </td>
        </tr>
        </table>
